home *** CD-ROM | disk | FTP | other *** search
- /*
- File: History.c
-
- Copyright 1991-6, Adobe Systems Incorporated.
- All rights reserved.
-
- C source file for Windows specific code for History example.
- */
-
- #include "History.h"
-
- /****************************************************************************/
-
- void CheckAndEnable (GPtr globals, const HWND hDlg, int16 *currentResources, Str255 hS);
- void UpdateHistories(GPtr globals, const HWND hDlg, short count, Str255 hS);
-
- /*****************************************************************************/
-
- void DoAbout (GPtr globals)
- {
- ShowAbout((AboutRecordPtr)gStuff, hDllInstance, AboutID);
- }
-
- /*****************************************************************************/
- // This routine checks our values and update them accordingly whenever a
- // button gets pressed, so this routine will update the resources and populate
- // the dialog.
-
- void CheckAndEnable (GPtr globals, const HWND hDlg, int16 *currentResources, Str255 hS)
- {
-
- *currentResources = CountPIResources(histResource);
-
- if (gCurrentHistory < 1)
- gCurrentHistory = 1;
-
- if (gCurrentHistory > *currentResources)
- gCurrentHistory = *currentResources;
-
- if (*currentResources <= histTotal ||
- gCurrentHistory+histTotal > *currentResources)
- {
- if (GetFocus() == GetDlgItem(hDlg, downButton))
- SetDialogDefaultItem(hDlg, ok); // set focus to OK since we're disabling
- DisableControl (hDlg, downButton); // nothing extra to show
- }
- else
- EnableControl (hDlg, downButton);
-
-
- if (gCurrentHistory < 2)
- {
- if (GetFocus() == GetDlgItem(hDlg, upButton))
- SetDialogDefaultItem(hDlg, ok); // set focus to OK since we're disabling
- DisableControl (hDlg, upButton);
- }
- else
- EnableControl (hDlg, upButton);
-
- if (*currentResources >= gCurrentHistory && *currentResources > 0)
- { // enable trim buttons
- EnableControl (hDlg, trimFirst);
- EnableControl (hDlg, trimLast);
- }
- else
- { // disable trim buttons
- if (GetFocus() == GetDlgItem(hDlg, trimFirst) ||
- GetFocus() == GetDlgItem(hDlg, trimLast))
- SetDialogDefaultItem(hDlg, ok); // set focus to OK since we're disabling
- DisableControl (hDlg, trimFirst);
- DisableControl (hDlg, trimLast);
- }
-
- UpdateHistories(globals, hDlg, *currentResources, hS);
- }
-
- /*****************************************************************************/
-
- BOOL WINAPI ExportProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam) // Win32 Change
- {
- int item, cmd;
- short numberErr = 0;
- int32 x = 0;
- static Str255 hS = ""; //histstatus
- static int16 currentResources = 0; // static so retains value on calls
- static int lastItem = 0;
- static GPtr globals = NULL; /* need to be static */
-
- switch (wMsg)
- {
-
- case WM_INITDIALOG:
-
- /* set up globals */
-
- globals = (GPtr) lParam;
-
- CenterDialog(hDlg);
-
- PIGetString(hS, kHistStatus); // get status string
-
- CheckAndEnable (globals, hDlg, ¤tResources, hS);
- /* drop into PAINT */
- case WM_PAINT:
- // return FALSE;
- break;
-
- case WM_COMMAND:
- item = COMMANDID (wParam); // WIN32 Change
- cmd = HIWORD (wParam);
-
- switch (item)
- {
- case trimFirst:
- if (cmd == BN_CLICKED)
- {
- if (currentResources >= gCurrentHistory)
- {
- DeletePIResource (histResource, gCurrentHistory);
- gStuff->dirty = TRUE;
- }
- CheckAndEnable (globals, hDlg, ¤tResources, hS);
- // checks buttons and values
- break;
- }
- case trimLast:
- if (cmd == BN_CLICKED)
- {
- if (currentResources >= gCurrentHistory + histTotal-1)
- {
- DeletePIResource (histResource,
- (short)(gCurrentHistory + histTotal-1));
- gStuff->dirty = TRUE;
- }
- else if (currentResources > 0)
- {
- DeletePIResource (histResource,
- (short)(currentResources));
- gStuff->dirty = TRUE;
- }
- CheckAndEnable (globals, hDlg, ¤tResources, hS);
- // checks buttons and values
- break;
- }
- case upButton:
- if (cmd == BN_CLICKED)
- {
- gCurrentHistory--;
- CheckAndEnable (globals, hDlg, ¤tResources, hS);
- break;
- }
- case downButton:
- if (cmd == BN_CLICKED)
- {
- gCurrentHistory++;
- CheckAndEnable (globals, hDlg, ¤tResources, hS);
- break;
- }
- case ok:
- if (cmd == BN_CLICKED)
- {
- EndDialog(hDlg, item);
- return TRUE;
- }
- break;
- case cancel:
- if (cmd == BN_CLICKED)
- {
- gResult = userCanceledErr;
- EndDialog(hDlg, item); // WIN32 change
- return TRUE;
- }
- // don't ever validate during cancel
- break;
- default:
- return FALSE;
- break;
- } // switch (item)
- break; // case WM_COMMAND
- } // switch
-
- return FALSE;
- }
-
- /*****************************************************************************/
- short DoParameters (GPtr globals)
- {
-
- int nResult;
- PlatformData *platform;
-
- platform = ((ExportRecordPtr) gStuff)->platformData;
-
- /* Query the user for percent dissolve. */
-
- nResult = DialogBoxParam(hDllInstance,
- (LPSTR)"HISTORYPARAM",
- (HWND)platform->hwnd,
- (FARPROC)ExportProc,
- (LPARAM)globals);
-
- return (nResult == ok);
-
- }
-
- /****************************************************************************/
- /* Populate dialog with history strings. */
-
- void UpdateHistories (GPtr globals, const HWND hDlg, short count, Str255 hS)
- {
- Str255 s = "";
-
- Str255 n1 = ""; // for "^0 to ^1 of ^2"
- Str255 n2 = ""; //
- Str255 nT = ""; //
- Str255 ss = ""; //
-
- long x = gCurrentHistory + (histTotal - 1);
- short loop;
-
- PICopy(ss, hS, hS[0]+1); // make a new copy
-
- for (loop = gCurrentHistory; loop < gCurrentHistory + histTotal; loop++)
- {
- GetHistory (globals, loop, s);
- if (loop == gCurrentHistory && !s[0])
- {
- PIGetString(s, kNoHistories);
- ss[ (ss[0] = 0)+1 ] = 0; // none
- }
- StuffText (hDlg, (short)(histItem1 + (loop - gCurrentHistory)), s);
- if (s[0] < 1 && x > loop-1)
- x = loop-1;
- }
-
- if (ss[0] > 0)
- { // got the display string. Populate it.
- NumToString(gCurrentHistory, n1);
- NumToString(x, n2);
- NumToString(count, nT);
- PIParamText(ss, n1, n2, nT);
- }
- StuffText (hDlg, statusText, ss);
- // even if nothing, stuff empty or string in field
- }
-
- /****************************************************************************/
- /* Example for ShowAlert() function which takes a string ID as parameter */
- /* and displays a message box */
- /****************************************************************************/
-
- short ShowAlert (short stringID)
- {
- char szMessage[256];
- char szTitle[128];
-
- LoadString(hDllInstance, stringID, szMessage, sizeof szMessage);
- LoadString(hDllInstance, 2, szTitle, sizeof szTitle);
- return ( MessageBox((HWND)NULL, (LPSTR)szMessage, (LPSTR)szTitle, MB_OK | MB_ICONHAND) );
-
- }
-
- /*****************************************************************************/
-
- /* Initialization and termination code for window's dlls. */
-
- /* ------------------------------------------------
- * Code from Borland's window's dll example code.
- * ------------------------------------------------
- */
- #if defined(__BORLANDC__)
- // Turn off warning: Parameter '' is never used; effects next function only
- #pragma argsused
- #endif
-
- #ifdef WIN32
-
- // Every 32-Bit DLL has an entry point DLLInit
-
- BOOL APIENTRY DLLInit(HANDLE hInstance, DWORD fdwReason, LPVOID lpReserved)
- {
-
- if (fdwReason == DLL_PROCESS_ATTACH)
- hDllInstance = hInstance;
-
- return TRUE; // Indicate that the DLL was initialized successfully.
- }
-
- #else
- // Every 16-Bit DLL has an entry point LibMain and an exit point WEP.
- int FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSegment,
- WORD wHeapSize, LPSTR lpszCmdLine )
- {
- // Required when using Zortech; causes blink to include startup code
- extern __acrtused_dll;
-
- // The startup code for the DLL initializes the local heap (if there is one)
- // with a call to LocalInit which locks the data segment.
- if ( wHeapSize != 0 )
- UnlockData( 0 );
-
- hDllInstance = hInstance;
- return 1; // Indicate that the DLL was initialized successfully.
- }
-
- int FAR PASCAL WEP(int nParam)
- {
- switch (nParam) {
- case WEP_SYSTEM_EXIT: // System shutdown in progress
- case WEP_FREE_DLL : // DLL use count is 0
- default : // Undefined; ignore
- return 1;
- }
- }
- #endif
- /*****************************************************************************/
-
-
-